﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading.Tasks;

namespace IntelligentGateway.SmartCommunity.BUS
{
    public class DeviceBUS
    {
        public string PingTest(string ip)
        {
            Ping ping = new Ping();
            PingReply pingReply = ping.Send(ip);
            string replay;
            if (pingReply.Status == IPStatus.Success)
            {
                replay = "当前在线，已ping通！";
            }
            else
            {
                replay = "不在线，ping不通！";
            }
            return replay;
        }

        public string GetLocalMac()
        {
            string macAddress = "";
            try
            {
                foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
                {
                    if (nic.OperationalStatus == OperationalStatus.Up)
                    {
                        macAddress = nic.GetPhysicalAddress().ToString();
                        IPInterfaceProperties ipProperties = nic.GetIPProperties();
                        UnicastIPAddressInformation curIP = ipProperties.UnicastAddresses[0];
                        string ip = curIP.Address.ToString();
                        string mask = curIP.IPv4Mask.ToString();
                        string server = ipProperties.GatewayAddresses[0].Address.ToString();
                        break;
                    }
                }
                return macAddress;
            }
            catch
            {
                return "";
            }
        }
    }
}
